<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function s()
{
    echo '测试入口文件里调用方法';
}

/**
 * API通用化接口数据返回
 * @param int $status    业务状态码
 * @param string $message   信息提示
 * @param [] $data      返回数据
 * @param int $httpcode  http状态码
 * @return array
 */
function show($status,$message,$data=[],$httpcode=200)
{
   $arr = [
        'status' => $status,
        'message'=> $message,
        'data'   => $data
    ];
   /*$arr = [
       'status'  => $status,
       'message' => $message
   ];
   if(!empty($dataarr))
   {
       $arr['data'] = $dataarr;
   }*/
   return json($arr,$httpcode);
}


function pagination($obj)
{
    if(!$obj)
    {
        return '';
    }

    $params = request()->param();
    return '<div class="imooc-app">'.$obj->appends($params)->render().'</div>';
    /* 分页展示:这是去模板页面调用的方式
    {:pagination($news)}*/
}

/**
 * 获取栏目名称
 * @param $catId
 */
function getCatName($catId)
{
    if(!$catId) {
        return '';
    }
    $cats = config('cat.lists');

    return !empty($cats[$catId]) ? $cats[$catId] : '';
}

/**
 * 后台是否推荐 替换掉数据库里查询出来的数据
 * @param $str
 * @return string
 */
function isYesNo($str)
{
   return $str ? '<span style="color:red">是</span>' : '<span>否</span>';
}